package cn.gene.store.order.webapi.controller;

import cn.gene.store.order.service.IOmsOrderService;
import cn.gene.timeyan.common.restful.JsonResult;
import cn.gene.timeyan.pojo.store.order.dto.ExchangeOrderDTO;
import cn.gene.timeyan.pojo.store.order.dto.OrderAddDTO;
import cn.gene.timeyan.pojo.store.order.vo.OrderAddVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.spring.web.json.Json;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 订单模块*
 *
 * @author LWG
 * @date 2022/7/23 12:58
 * @since 1.0.0@gene.cn
 */
@RestController
@RequestMapping("/oms/order")
@Api(tags="订单功能")
public class OmsOrderController {
    @Autowired
    IOmsOrderService iOmsOrderService;

    @PostMapping("/add-new")
    @ApiOperation("下单")
    public JsonResult<OrderAddVO> addNew(@Valid @RequestBody OrderAddDTO orderAddDTO){
        OrderAddVO orderAddVO = iOmsOrderService.addOrder(orderAddDTO);
        return JsonResult.ok(orderAddVO);
    }

    @PostMapping("/exchange")
    @ApiOperation("兑换")
    public JsonResult<Void> exchangeOrder(@Valid @RequestBody ExchangeOrderDTO exchangeOrderDTO){
        iOmsOrderService.exchange(exchangeOrderDTO);
        return JsonResult.ok();
    }
}
